var express = require('express');
var router = express.Router();
//引入阿里云短信服务模块
const SMSClient = require('@alicloud/sms-sdk')
router.post('/get_sms', async (req, res, next) => {
	let {phoneNum,username,time,minute} = req.body;  //获取前端参数phone
	console.log(req.body,789);
	// let user=await userModel.find({phone:phoneNum})
	//初始化sms_client
	let smsClient = new SMSClient({
		accessKeyId: 'LTAI5tDDc6oj7snEn7AJ9TEn'
		,  //accessKeyId 前面提到要准备的
		secretAccessKey: 'GsM4KVKvm0GmQaQuaAiZAlbN3UoMeh'  //secretAccessKey 前面提到要准备的
	});

	// 开始发送短信
	smsClient.sendSMS({
		PhoneNumbers: parseInt(phoneNum),
		SignName: "约拍", //签名名称 前面提到要准备的
		TemplateCode: "SMS_466345004", //模版CODE  前面提到要准备的
		TemplateParam: `{"name":'${username}',"time":'${time+' '+minute}'}`, //  短信模板变量对应的实际值，JSON格式
	}).then(result => {
		console.log("result", result)
		let { Code } = result;
		if (Code == 'OK') {
			res.send({
				code: 0,
				msg: 'success',
				username,
				time,
			})
			console.log(result,123)
		}
	}).catch(err => {
		console.log(err);
		res.json({
			code: 1,
			msg: 'fail: ' + err.data.Message
		})
	})

});

module.exports = router;

